package com.incar.chuxing.utils.Dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.incar.chuxing.R;
import com.incar.chuxing.application.MyApplication;
import com.incar.chuxing.bean.CurrentFeeBean;
import com.incar.chuxing.utils.ImageLoader;

import java.util.List;


public class CarCurrentParkFeeDialog extends Dialog {

    private List<CurrentFeeBean.AttachmentBean.ListBean> list;
    private Context mContext;

    public CarCurrentParkFeeDialog(Context context) {
        super(context, R.style.MyDialog);
        mContext = context;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_layout_parkfee);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(true);
        setCancelable(true);
        //初始化界面控件
        initView();
    }


    /**
     * 初始化界面控件
     */
    private void initView() {
        RecyclerView currentFeeRc = findViewById(R.id.current_fee_rc);
        currentFeeRc.setLayoutManager(new LinearLayoutManager(mContext));
        CurrentFeeAdapter currentFeeAdapter = new CurrentFeeAdapter(list);
        currentFeeRc.setAdapter(currentFeeAdapter);
    }

    public void setData(List<CurrentFeeBean.AttachmentBean.ListBean> list) {
        this.list = list;
    }


    class CurrentFeeAdapter extends BaseQuickAdapter<CurrentFeeBean.AttachmentBean.ListBean, BaseViewHolder> {
        public CurrentFeeAdapter(List<CurrentFeeBean.AttachmentBean.ListBean> data) {
            super(R.layout.item_current_fee, data);
        }

        @Override
        protected void convert(final BaseViewHolder helper, CurrentFeeBean.AttachmentBean.ListBean item) {
            helper.setText(R.id.current_title, item.getTitle());
            helper.setText(R.id.current_content, item.getContent());
            if (helper.getAdapterPosition() == 0) {
                helper.setGone(R.id.current_line, true);
            } else {
                helper.setGone(R.id.current_line, false);
            }

            if (!TextUtils.isEmpty(item.getDes())) {
                helper.setGone(R.id.current_subtitle, true);
                helper.setText(R.id.current_subtitle, item.getDes());
            } else {
                helper.setGone(R.id.current_subtitle, false);
            }
            if (!TextUtils.isEmpty(item.getImg())) {
                helper.setGone(R.id.current_pic, true);
                ImageLoader.getInstance().displayImage(mContext, ((MyApplication) MyApplication.getInstance()).getImageUrl() + item.getImg(),
                        helper.getView(R.id.current_pic));
            } else {
                helper.setGone(R.id.current_pic, false);
            }
        }
    }
}
